![]() |
Introducing Functions
OPENING QUESTION: What is a function and how is it used in computer programming? There are actually several terms that are sometimes used that mean the same thing as a function:
OBJECTIVES: I will work to edit two different programs that each use functions in a different way during today's class. I will work with animation for the first time today. Review CALENDAR: WORDS O' THE DAY:
WORK O' THE DAY: Functions are a massively important aspect of programming in EVERY programming language. Functions are a great example of a software *abstraction*. By that I mean that functions take code that is:
Functions are usually looked at/processed by the system (the compiler!) FIRST and are read into memory before the rest of your program is processed by the compiler. Some languages require that functions to be defined FIRST in your code. Other programs make you place functions at the END of your code. Still other programs don't really care if you place them first or last! HERE is an example of a basic function. Please take a few moments and FULLY comment that code. Notice that the code is a bit weak. The onEvent listeners are not set particularly well. For example just starting to type causes the "Data Entry Received" msg to fire off. Can you make it work a bit more cleanly? HERE is a more advanced animation program. Notice the use of the timedLoop function!!! |